import java.io.*;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;


public class 飞行路线 {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int MAXN = 10001;
    public static int MAXM = 100001;
    public static int[] head = new int[MAXN];
    public static int[] next = new int[MAXM];
    public static int[] to = new int[MAXM];
    public static int[] weight = new int[MAXM];
    public static int cnt;
    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        int start = in.nextInt();
        int end = in.nextInt();
        // 建图
        cnt = 1;
        while (m-- > 0){
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            // 一定要建双向图
            addEdge(a,b,c);
            addEdge(b,a,c);
        }

        // 到每个点的最小花费, n 是点 k 是使用了免费
        int[][] distance = new int[n][k + 1];
        for (int[] a : distance) {
            Arrays.fill(a,Integer.MAX_VALUE);
        }
        boolean[][] vis = new boolean[n][k + 1];
        distance[start][0] = 0;
        PriorityQueue<int[]> heap = new PriorityQueue<>((a,b) -> a[2] - b[2]);
        heap.add(new int[]{start,0,0});
        while (!heap.isEmpty()) {
            int[] t = heap.poll();
            int u = t[0];
            int use = t[1];
            int cost = t[2];
            if (vis[u][use]) {
                continue;
            }
            if (u == end) {
                out.println(cost);
                out.close();
                return;
            }
            vis[u][use] = true;
            for (int i = head[u]; i != 0; i = next[i]) {
                int v = to[i]; // 到达的下一个点
                int w = weight[i]; // 需要的代价
                // 免费一次
                if (use < k && distance[u][use] <  distance[v][use + 1]) {
                    distance[v][use + 1] = distance[u][use];
                    heap.add(new int[]{v,use + 1,distance[v][use + 1]});
                }
                // 不免费
                if (distance[u][use] + w < distance[v][use]) {
                    distance[v][use] = distance[u][use] + w;
                    heap.add(new int[]{v,use,distance[v][use]});
                }
            }
        }
        out.print(-1);
        out.close();
    }

    private static void addEdge(int a, int b, int c) {
        next[cnt] = head[a];
        head[a] = cnt;
        to[cnt] = b;
        weight[cnt++] = c;
    }


    public static class Read // 自定义快速读入
    {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException
        {
            while(!st.hasMoreTokens())
            {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        String nextLine() throws IOException
        {
            return bf.readLine();
        }

        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
}
